<?php

namespace App\Jobs;

use App\Logic\ConfigLogic;
use EasyWeChat\Factory;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class SendTempMessage implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $message;

    /**
     * SendTempMessage constructor.
     * @param array $message
     */
    public function __construct($message)
    {
        $this->message = $message;
    }

    /**
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
     */
    public function handle()
    {
        $config = ConfigLogic::getWxConfig();
        $app = Factory::miniProgram($config);
        $re = $app->template_message->send($this->message);

        logger('tempMessage',$re);
    }
}
